<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button v-if="row._can_edit_" @click="to_edit(row)" size="small" type="primary">编辑</el-button>
      <el-button v-else-if="can_info" @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import {_config, _url_api, param_encode, to_string} from "@/js/s94_tool.js";
import {use_config_map} from "@/store/config_map.js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');
    if(in_right_admin('Page/add')) btns['添加'] = function(){ iframe({href:'/page/edit', width:'95%'}) }
    if(in_right_admin('Page/delete')) btns['彻底删除'] = function(){ app.$refs['list_url'].delete() }
    const channel_map = use_config_map().status_alias_map?.page?.channel || {};
    let forms_config = {
      title: {label:'标题',name:'where[title][like]',type:'text_one',value:''},
      url: {label:'URL',name:'where[url][like]',type:'text_one',value:''},
    };
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', order:true},
      title: {name:'title', label:'标题', width:'260px'},
      channel: {name:'channel', label:'所属渠道', type:'radio', config:channel_map, width:'100px'},
      type: {name:'type', label:'类型', type:'radio', config:'默认|,首页|index,个人中心|user_index', width:'100px'},
      url: {name:'url', label:'URL', min_width:'120px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'60px', type:'action', fixed:'right'};

    let tenant_id = _config('this_tenant.id');
    let can_edit = in_right_admin('Page/edit');
    return {
      can_edit,
      config: {
        api: '/admin/page/'+(is_del?'recycle':'list'),
        title: "页面列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          list.forEach(row=>{
            row._can_edit_ = can_edit && ~[0,row.tenant_id].indexOf(tenant_id)
          })
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
    }
  },
  methods: {
    action_list(row){
      const list = [
        {title:'', type:'', onClick:()=>{}, }
      ]
    },
    to_edit(row){
      let param = {
        id: row.id,
      }
      if (!row._can_edit_) param['is_info'] = 1;
      iframe({href:'page/edit?'+param_encode(param), width:'95%'})
    },
  },
  computed: {
    can_info(){
      console.log('can_info')
      return in_right_admin('Page/info')
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
